import 'package:niuniu_lulu/index/index.dart';
import 'package:niuniu_lulu/index/model/app_theme.dart';
import 'package:provider/provider.dart';
import '../../home/index.dart';

class IndexPage extends StatefulWidget{
  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage>{
  Widget getGroup(){
    var widget = GroupsWidget();
    return widget;
  }


  @override
  Widget build(BuildContext context) {
    InputControllers4 model = Provider.of<InputControllers4>(context);
    return Scaffold(
      body: Container(
        margin: EdgeInsets.only(top: 24.w),
        child: Column(
          children: [
            ChildIndexWidget(tag: 1,),
            ChangeNotifierProvider(
              create: (_) => InputControllers4(),
              child: ChildIndexWidget(controllers: model,tag: 2,)
            ),
          ],
        ),
      ),
    );
  }
}


class ChildIndexWidget extends StatefulWidget {
  final InputControllers4 controllers;
  final int tag;
  ChildIndexWidget({this.controllers,this.tag});

  @override
  _ChildIndexWidgetState createState() => _ChildIndexWidgetState();
}

class _ChildIndexWidgetState extends State<ChildIndexWidget> {
  InputControllers4 _controllers4;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  List<Widget> getInputWidgets(AppTheme model){
    List<Widget> widgets = [];
    Widget input;
    if (widget.tag == 1){
      input = model.GroupOneAInputShow?InputsZone(type: GroupType.Group7):Container();
    }else{
      input = model.GroupOneBInputShow?InputsZone(type: GroupType.Group7):Container();
    }
    widgets.add(input);
    widgets.add(SizedBox(height: 20.h));
    widgets.add(Container(
        child: GroupsWidget(type: GroupType.Group7))
    );
    return widgets;
  }

  @override
  Widget build(BuildContext context) {
    if (widget.controllers != null){
      _controllers4 = Provider.of<InputControllers4>(context);
      widget.controllers.inputValueChanged = ((InputControllers4 model){
        _controllers4.controllerA.text = model.controllerA.text;
        _controllers4.controllerB.text = model.controllerB.text;
      });
    }
    return Consumer<AppTheme>(builder: (context,model,widget){
      return Column(children: getInputWidgets(model));
    });
  }
}



